<?php
namespace Home\Controller;
use Think\Controller;
class UsersModelController extends Controller {

	private $m='';
	public function _initialize(){
		if($this->m==''){
			$this->m = M('Users');
		}
	}


	//获取分页用户信息
	public function get_user_list($fields='',$where='',$order='users_id',$pcount=10){
		return Get_Fpage($this->m,$fields,$where,$order,$pcount);
	}


	//获取指定用户信息
	public function get_user_info($field='',$where=''){
		$data = $this->m->field($field)->where($where)->find();
		if($data){
			return $data;
		}
	}


	//更新或添加用户信息
	public function update_or_add($arr){
		if(count($arr) <=0){
			exit;
		}
		$st = $this->m->where(array('users_openid'=>$arr['users_openid']))->find();
		if($this->m->create($arr)){
			$data['oid'] = $arr['users_openid'];
			$data['ftime'] = time();
			$data['ip'] = $_SERVER["REMOTE_ADDR"];
			$st4 = M('Users_login')->data($data)->add();
			if($st){	
				$st2 = $this->m->where(array('users_openid'=>$arr['users_openid']))->data($arr)->save();
				if($st2){
					echo 'ok';exit;
				}else{
					echo 'e1';exit;
				}
			}else{
				$arr['users_ftime']= time();
				$st3 = $this->m->data($arr)->add();
				if($st3){
					echo 'ok';exit;
				}else{
					echo 'e2';exit;
				}
			}
		}
		echo 'e3';
	}

}